<!DOCTYPE html>

<head>
  <script src="/resources/testharness.js"></script>
  <script src="/resources/testharnessreport.js"></script>
  <script src="../resources/include-frames-helper.js"></script>
</head>

<body>
  <script>
    const verifyMainFrameEntries = (entries) => {
      let filterOptions = [
        createFilterOption('include-frames-originA-AA', 'navigation', 1, 'Main Frame'),
        createFilterOption('child-frame.html', 'navigation', 2, 'Child Frames'),
        createFilterOption('child-frame.html', 'resource', 2, 'Main Frame'),
        createFilterOption('mark_child_frame', 'mark', 2, 'Child frames')
      ];

      verifyEntries(entries, filterOptions);
    }

    const verifyPerformanceEntries = () => {
      const entries = performance.getEntries({ includeChildFrames: true });

      const navigationEntries = performance.getEntries({ entryType: "navigation", includeChildFrames: true });

      const markedEntries = performance.getEntries(
        { name: 'mark_child_frame', includeChildFrames: true });

      verifyMainFrameEntries(entries);

      // 1 entry for main frame, 1 for each child frame.
      assert_equals(navigationEntries.length, 3, 'Navigation entries should be 3.');

      // 1 entry for each child frame.
      assert_equals(markedEntries.length, 2, 'Mark entries should be 2.');
    }

    promise_test(async () => {
      performance.clearResourceTimings();

      // Load first child iframe.
      const promise1 = loadChildFrame('../resources/child-frame.html');

      // Load second child iframe.
      const promise2 = loadChildFrame('../resources/child-frame.html');

      return Promise.all([promise1, promise2]).then(verifyPerformanceEntries);
    }, 'GetEntries of a document of origin A and its two child frames both of origin A.');
  </script>
</body>
